/*

  SpringProx API
  --------------

  Copyright (c) 2000-2008 SpringCard - www.springcard.com

  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  PARTICULAR PURPOSE.

  History
  -------
  
  JDA 15/02/2003 : string list created from philips rc500/mv700 files
  JDA 16/05/2003 : added some strings
                   added helpers functions for Delphi and VB users

*/
#include "sprox_api_i.h"

/**f* SpringProxAPI/SPROX_GetLibrary
 *
 * NAME
 *   SPROX_GetLibrary
 *
 * DESCRIPTION
 *   Retrieve the SpringProxAPI version info
 *
 * INPUTS
 *   TCHAR *library     : buffer to receive the library info
 *   WORD  len          : character-size of the buffer
 *
 * RETURNS
 *   MI_OK              : success
 *
 * NOTES
 *   The function returns 
 *   - "SPRINGCARD SPRINGPROX/CSB <level> <version>"
 *
 *   <level> shows library capabilities :
 *   - 1        basic firmware
 *
 *   <version> is the version field, formatted "M.mm" as follow :
 *   - M        is the major release number (1 to 2 digits)
 *   - m        is the minor release number (1 to 3 digits)
 *
 * VARIANTS
 *   SPROX_GetLibraryA : ASCII version
 *   SPROX_GetLibraryW : UNICODE version
 *
 **/
SPROX_API_FUNC(GetLibrary) (TCHAR *library, WORD len)
{
#ifdef UNICODE
  return SPROX_API_CALL(GetLibraryW) (library, len);
#else
  return SPROX_API_CALL(GetLibraryA) (library, len);
#endif
}

SPROX_API_FUNC(GetLibraryA) (char *library, WORD len)
{
  char buffer[64];

#ifndef SPROX_API_REENTRANT
  sprintf(buffer, "SPRINGCARD SPRINGPROX API %X.%02X [%d]", SPROX_VERSION_MAJOR, SPROX_VERSION_MINOR, SPROX_API_BUILD);
#else
  sprintf(buffer, "SPRINGCARD SPRINGPROX-EX API %X.%02X [%d]", SPROX_VERSION_MAJOR, SPROX_VERSION_MINOR, SPROX_API_BUILD);
#endif
  
  SPROX_Trace(TRACE_ALL, buffer);

  if (library == NULL) return MI_LIB_CALL_ERROR;
  if (len == 0) return MI_LIB_CALL_ERROR;

  strncpy(library, buffer, len);
  library[len - 1] = '\0';
  return MI_OK;
}

SPROX_API_FUNC(GetLibraryW) (wchar_t *library, WORD len)
{
  char buffer[64];
  int i;  
  SWORD rc;
  if (len > 64) len = 64;
  rc = SPROX_API_CALL(GetLibraryA) (buffer, len);
  if (rc != MI_OK) return rc;
  for (i=0; i<len; i++) library[i] = buffer[i];
  return MI_OK;
}
